package com.josework.springhelloworld.entity.parallel;

import lombok.Data;
import org.apache.commons.lang3.function.TriFunction;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Supplier;

@Data
public class Student {
    private String name;
    private int age;
    private int score;

    public Student(){

    }

    public Student(int score){
        this.score = score;
    }

    public Student(String name,int age){
        this.name = name;
        this.age = age;

    }

    public Student(String name,int age,int score){
        this.name = name;
        this.age = age;
        this.score = score;
    }

    public static void main(String[] args) {
        //无参构造函数可以用Supplier
        Supplier<Student> c1 = Student::new;
        Student student = c1.get();

        //一个参数的构造函数可以用Function
        List<Integer> scores = Arrays.asList(100,98,78,89);
        Function<Integer,Student> f = Student::new;
        List<Student> students = map(scores, f);
        System.out.println(students);

        //两个参数的构造函数可以用BiFunction
        BiFunction<String, Integer, Student>  c2 = Student::new;
        Student y = c2.apply("y", 20);

        //三个参数的构造函数可以用TriFunction
        TriFunction<String, Integer, Integer, Student> c3 = Student::new;
        Student x = c3.apply("x", 26, 100);



    }

    public static List<Student> map(List<Integer> scores,Function<Integer,Student> f){
        Supplier<List<Student>> supplier = ArrayList::new;
        List<Student> list = supplier.get();
        for (Integer integer : scores) {
            Student apply = f.apply(integer);
            list.add(apply);
        }
        return list;
    }



}
